home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_10_01
/
1001014a
< prev
next >
Wrap
Text File
|
1991-11-16
|
632b
|
34 lines
Listing 2 -- the file fopen.c
/* fopen function */
#include <stdlib.h>
#include "xstdio.h"
FILE *(fopen)(const char *name, const char *mods)
{ /* open a file */
FILE *str;
size_t i;
for (i = 0; i < FOPEN_MAX; ++i)
if (_Files[i] == NULL)
{ /* setup empty _Files[i] */
str = malloc(sizeof (FILE));
if (str == NULL)
return (NULL);
_Files[i] = str;
str->_Mode = _MALFIL;
break;
}
else if (_Files[i]->_Mode == 0)
{ /* setup preallocated _Files[i] */
str = _Files[i];
break;
}
if (FOPEN_MAX <= i)
return (NULL);
return (_Foprep(name, mods, str));
}